package com.zonski.jbots.engine;

import java.util.Hashtable;
import java.util.Vector;

/**
 * Describes a class of entity
 */
public final class EntityType
{
    private static final QuickVector TYPES = new QuickVector(20);

    public static final EntityType getEntityType(int type)
    {
        return getEntityType(null, type);
    }

    public static final EntityType getEntityType(String name, int type)
    {
        EntityType entityType;
        if(TYPES.size() > type)
        {
            Object found = TYPES.elementAt(type);
            if(found instanceof EntityType)
            {
                entityType = (EntityType)found;
            }else{
                entityType = null;
            }
        }else{
            entityType = null;
        }
        if(entityType == null)
        {
            entityType = new EntityType(name, type);
            while(TYPES.size() <= type)
            {
                TYPES.addElement(new Object());
            }
            TYPES.setElementAt(entityType, type);
        }else if(entityType.name == null){
            entityType.name = name;
        }
        return entityType;
    }

    private String name;
    private int id;

    private EntityType(String name, int id)
    {
        this.name = name;
        this.id = id;
    }

    public final String getName()
    {
        return this.name;
    }

    public final int getId()
    {
        return this.id;
    }
}
